package com.fr.report.io;

import com.fr.report.PageSet;
import com.fr.report.PageSetChain;
import com.fr.report.ReportPage;
import com.fr.report.ResultWorkBook;
import com.fr.report.core.ReportUtils;
import com.fr.report.painter.PagePainter;
import java.awt.Graphics2D;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

public class SVGExporter extends AbstractAppExporter
{
  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook)
    throws Exception
  {
    PageSet localPageSet = paramResultWorkBook.generateReportPageSet(ReportUtils.getPaperSettingListFromWorkBook(paramResultWorkBook)).getTraversingCase();
    export(paramOutputStream, localPageSet);
    localPageSet.release();
  }

  public void export(OutputStream paramOutputStream, PageSet paramPageSet)
    throws Exception
  {
    DOMImplementation localDOMImplementation = GenericDOMImplementation.getDOMImplementation();
    Document localDocument = localDOMImplementation.createDocument(null, "svg", null);
    SVGGraphics2D localSVGGraphics2D = new SVGGraphics2D(localDocument);
    int i = 0;
    for (int j = 0; j < paramPageSet.size(); ++j)
    {
      ReportPage localReportPage = paramPageSet.getPage(j);
      if (localReportPage == null)
        break;
      double d1 = 0.75D;
      double d2 = d1 * localReportPage.getPageWidth();
      double d3 = d1 * localReportPage.getPageHeight();
      Graphics2D localGraphics2D = (Graphics2D)localSVGGraphics2D.create(0, i, (int)d2, (int)d3);
      localGraphics2D.scale(d1, d1);
      new PagePainter(localReportPage, localGraphics2D, false).convert();
      i += (int)d3;
      localGraphics2D.dispose();
    }
    OutputStreamWriter localOutputStreamWriter = new OutputStreamWriter(paramOutputStream, "UTF-8");
    localSVGGraphics2D.stream(localOutputStreamWriter, true);
    paramOutputStream.flush();
  }
}